package com.efounder.util;

import com.efounder.constant.EnvironmentVariable;

import static com.efounder.frame.utils.Constants.CHAT_PASSWORD;
import static com.efounder.frame.utils.Constants.CHAT_USER_ID;

/**
 * env取值判断是否支持某功能
 */
public class EnvSupportManager {


    private static Boolean isSupportBanSpeak = null;
    private static Boolean isSupportShareGroup = null;
    private static Boolean isShowGroupWorkAddressMenu = null;
    private static Boolean isSupportRecallMessage = null;
    private static Boolean isSupportShareMessage = null;
    private static Boolean isSupportSearchMessage = null;
    private static Boolean isSupportSetStrangerChat = null;
    private static Boolean isSupportBadgeDrag = null;
    private static Boolean isSupportRecognizeVoiceSend = null;
    private static Boolean isSupportMentionSomeone = null;
    private static Boolean isSupportAboutShowGuide = null;
    private static Boolean isSupportShowMutiDevice = null;
    private static Boolean isSupportShareWebUrl = null;
    private static Boolean isSupportShowInputting = null;
    private static Boolean isSupportListenScreenShot = null;
    private static Boolean isSupportShowIntergral = null;
    private static Boolean isSupportCWGXPage = null;
    private static Boolean isSupportMultiLanguage = null;
    private static Boolean isSupportTranslate = null;
    private static Boolean isSupportGooglePlayUpgrade = null;
    private static Boolean isLoginOwn = null;
    private static Boolean isSupportIM = null;
    private static Boolean isSupportIMForegroundService = null;
    private static Boolean isSupportSkin = null;
    private static Boolean showLeftSetting = null;
    private static Boolean isSupportNfcWallet = null;
    private static Boolean isSupportForceBleNfc = null;
    private static Boolean isSupportFloatWindow = null;
    private static Boolean isSupportChatSetting = null;
    private static Boolean isSupportShareFriendOrField = null;
    private static Boolean isUseTransparentStatus = null;
    private static Boolean isSupportHDWallet = null;
    private static Boolean isAssetHasMsg = null;
    private static Boolean  showofficialChatInput= null;
    private static Boolean  isSupportUploadPrivateKey= null;


    //是否支持群禁言chatschats
    public static boolean isSupportBanSpeak() {
        if (isSupportBanSpeak == null) {
            isSupportBanSpeak = checkEnvVariable("supportBanSpeak", "1", "0");
            ;
        }

        return isSupportBanSpeak;
    }

    //是否支持分享群组功能
    public static boolean isSupportShareGroup() {
        if (isSupportShareGroup == null) {
            isSupportShareGroup = checkEnvVariable("supportshareGroup", "1", "0");
        }
        return isSupportShareGroup;
    }

    //群设置界面是否显示群工作地址设置
    public static boolean isShowGroupWorkAddressMenu() {
//        return (EnvironmentVariable.getProperty("supportCWGXPage", "0").equals("1"));
        if (isShowGroupWorkAddressMenu == null) {
            isShowGroupWorkAddressMenu = checkEnvVariable("showGroupWorkAddressMenu", "1", "0");
        }

        return isShowGroupWorkAddressMenu;
    }

    //是否支持撤回消息
    public static boolean isSupportRecallMessage() {
        if (isSupportRecallMessage == null) {
            isSupportRecallMessage = checkEnvVariable("supportRecallMessage", "1", "0");
        }

        return isSupportRecallMessage;
    }

    //是否支持分享消息
    public static boolean isSupportShareMessage() {
        if (isSupportShareMessage == null) {
            isSupportShareMessage = checkEnvVariable("supportShareMessage", "1", "0");
        }

        return isSupportShareMessage;
    }

    //是否支持消息过滤（查询 暂时用在应用号）
    public static boolean isSupportSearchMessage() {
        if (isSupportSearchMessage == null) {
            isSupportSearchMessage = checkEnvVariable("supportSearchMessage", "1", "0");
        }

        return isSupportSearchMessage;
    }

    //是否支持设置陌生人聊天
    public static boolean isSupportSetStrangerChat() {
        if (isSupportSetStrangerChat == null) {
            isSupportSetStrangerChat = checkEnvVariable("supportStrangerChat", "1", "0");
        }

        return isSupportSetStrangerChat;
    }

    //是否支持拖拽角标清除
    public static boolean isSupportBadgeDrag() {
        if (isSupportBadgeDrag == null) {
            isSupportBadgeDrag = checkEnvVariable("supportBadgeDrag", "1", "0");
        }
        return isSupportBadgeDrag;
    }

    //是否支持发送识别语音发送
    public static boolean isSupportRecognizeVoiceSend() {
        if (isSupportRecognizeVoiceSend == null) {
            isSupportRecognizeVoiceSend = checkEnvVariable("supportRecognizeVoiceSend", "1", "0");
        }
        return isSupportRecognizeVoiceSend;
    }

    /**
     * 是否支持@提及功能
     */
    public static boolean isSupportMentionSomeone() {
        if (isSupportMentionSomeone == null) {
            isSupportMentionSomeone = checkEnvVariable("support@", "1", "0");

        }
        return isSupportMentionSomeone;
    }

    /**
     * 是否支持关于页面显示启动页
     */
    public static boolean isSupportAboutShowGuide() {
        if (isSupportAboutShowGuide == null) {
            isSupportAboutShowGuide = checkEnvVariable("supportAboutShowGuide", "1", "0");
        }
        return isSupportAboutShowGuide;
    }

    /**
     * 是否支持显示多设备登录列表
     */
    public static boolean isSupportShowMutiDevice() {
        if (isSupportShowMutiDevice == null) {
            isSupportShowMutiDevice = checkEnvVariable("supportShowMutiDevice", "1", "0");
        }
        return isSupportShowMutiDevice;
    }

    /**
     * 是否支持分享网页 chatwebviewactivity右上角分享
     */
    public static boolean isSupportShareWebUrl() {
        if (isSupportShareWebUrl == null) {
            isSupportShareWebUrl = checkEnvVariable("isSupportShareWebUrl", "1", "0");
        }
        return isSupportShareWebUrl;
    }

    /**
     * 是否显示对方正在输入中(支持的话就会发送)
     */
    public static boolean isSupportShowInputting() {
        if (isSupportShowInputting == null) {
            isSupportShowInputting = checkEnvVariable("showInputting", "1", "0");
        }
        return isSupportShowInputting;
    }

    /**
     * 是否支持截屏后显示分享好友的dialog
     */
    public static boolean isSupportListenScreenShot() {
        if (isSupportListenScreenShot == null) {
            isSupportListenScreenShot = checkEnvVariable("listenScreenShot", "1", "0");
        }
        return isSupportListenScreenShot;
    }

    /**
     * 是否显示对话积分以及银钻图标，默认不显示
     */
    public static boolean isSupportShowIntergral() {
        if (isSupportShowIntergral == null) {
            isSupportShowIntergral = checkEnvVariable("showIntergral", "1", "0");
        }
        return isSupportShowIntergral;
    }

    /**
     * 是否支持显示财务共享特有界面
     * 联系人跳转添加好友
     * 个人详情
     * 群应用全部移除
     */
    public static boolean isSupportCWGXPage() {
        if (isSupportCWGXPage == null) {
            isSupportCWGXPage = checkEnvVariable("supportCWGXPage", "1", "0");
        }
        return isSupportCWGXPage;
    }

    /**
     * 是否支持多语言切换
     *
     * @return
     */
    public static boolean isSupportMultiLanguage() {
        if (isSupportMultiLanguage == null) {
            isSupportMultiLanguage = checkEnvVariable("supportMultiLanguage", "1", "0");
        }
        return isSupportMultiLanguage;
    }


    /**
     * 是否支持翻译服务
     *
     * @return
     */
    public static boolean isSupportTranslate() {
        if (isSupportTranslate == null) {
            isSupportTranslate = checkEnvVariable("supportTranslate", "1", "0");
        }
        return isSupportTranslate;
    }

    /**
     * 是否支持google play升级应用
     */
    public static boolean isSupportGooglePlayUpgrade() {
        if (isSupportGooglePlayUpgrade == null) {
            isSupportGooglePlayUpgrade = checkEnvVariable("supportGooglePlayUpgrade", "1", "0");
        }
        return isSupportGooglePlayUpgrade;
    }

    /**
     * 是否是独立登录（登录与检查版本的接口分离，默认不是独立登录）
     */
    public static boolean isLoginOwn() {
        if (isLoginOwn == null) {
            isLoginOwn = checkEnvVariable("loginOwn", "1", "0");
        }

        return isLoginOwn;
    }

    /**
     * 是否支持Im消息服务 默认支持
     */
    public static boolean isSupportIM() {
        if (isSupportIM == null) {
            isSupportIM = checkEnvVariable("supportIM", "1", "1");
        }
        if (!isSupportIM) {
            //不支持IM 存入无效的 im帐号密码
            EnvironmentVariable.setProperty(CHAT_USER_ID, "0");
            EnvironmentVariable.setProperty(CHAT_PASSWORD, "0");
            EnvironmentVariable.setUserID("0");
        }
        return isSupportIM;
    }

    /**
     * 是否支持Im消息通知栏前台服务
     */
    public static boolean isSupportIMForegroundService() {
        if (isSupportIMForegroundService == null) {
            isSupportIMForegroundService = checkEnvVariable("supportIMForeService", "1", "0");
        }

        return isSupportIMForegroundService;
    }

    /**
     * 是否支持换肤 默认不支持
     */
    public static boolean isSupportSkin() {
        if (isSupportSkin == null) {
            isSupportSkin = checkEnvVariable("supportSkin", "1", "0");
        }
        return isSupportSkin;
    }

    /**
     * 是否显示侧滑的设置菜单
     */
    public static boolean showLeftSetting() {
        if (showLeftSetting == null) {
            showLeftSetting = checkEnvVariable("showLeftSetting", "1", "0");
        }
        return showLeftSetting;
    }

    /**
     * 是否支持手机自身NFC读写冷钱包功能
     */
    public static boolean isSupportNfcWallet() {
        if (isSupportNfcWallet == null) {
            isSupportNfcWallet = checkEnvVariable("supportNfcWallet", "1", "0");
        }
        return isSupportNfcWallet;
    }

    public static boolean isSupportForceBleNfc() {
        if (isSupportForceBleNfc == null) {
            isSupportForceBleNfc = checkEnvVariable("supportForceBleNfc", "1", "0");
        }
        return isSupportForceBleNfc;
    }

    /**
     * 是否支持应用悬浮窗
     */
    public static boolean isSupportFloatWindow() {
        if (isSupportFloatWindow == null) {
            isSupportFloatWindow = checkEnvVariable("supportFloatWindow", "1", "0");
        }
        return isSupportFloatWindow;
    }

    /**
     * 是否支持显示聊天界面右上角的设置菜单按钮
     */
    public static boolean isSupportChatSetting() {
        if (isSupportChatSetting == null) {
            isSupportChatSetting = checkEnvVariable("supportChatSetting", "1", "1");
        }
        return isSupportChatSetting;
    }

    /**
     * 是否支持新闻资讯分享弹窗显示分享好友和引力场
     */
    public static boolean isSupportShareFriendOrField() {
        if (isSupportShareFriendOrField == null) {
            isSupportShareFriendOrField = checkEnvVariable("isSupportShareFriendOrField", "1", "0");
        }
        return isSupportShareFriendOrField;
    }

    /**
     * 是否使用透明状态栏
     */
    public static boolean isUseTransparentStatus() {
        if (isUseTransparentStatus == null) {
            isUseTransparentStatus = checkEnvVariable("useTransparentStatus", "1", "0");
        }
        return isUseTransparentStatus;
    }

    /**
     * 是否支持HD钱包
     *
     * @return
     */
    public static boolean isSupportHDWallet() {
        if (isSupportHDWallet == null) {
            isSupportHDWallet = checkEnvVariable("isSupportHDWallet", "1", "0");
        }
        return isSupportHDWallet;
    }
    /**
     * 是否支持上传子钱包私钥
     *
     * @return
     */
    public static boolean isSupportUploadPrivateKey() {
        if (isSupportUploadPrivateKey == null) {
            isSupportUploadPrivateKey = checkEnvVariable("isSupportUploadPrivateKey", "1", "0");
        }
        return isSupportUploadPrivateKey;
    }

    /**
     * 资产界面是否有消息入口
     *默认没有
     * @return
     */
    public static boolean isAssetHasMsg() {
        if (isAssetHasMsg == null) {
            isAssetHasMsg = checkEnvVariable("isAssetHasMsg", "1", "0");
        }
        return isAssetHasMsg;
    }

    /**
     * 是否显示应用号（公众号）聊天输入框
     *默认有
     * @return
     */
    public static boolean supportOfficialChatInput() {
        if (showofficialChatInput == null) {
            showofficialChatInput = checkEnvVariable("showOfficialChatInput", "1", "1");
        }
        return showofficialChatInput;
    }
    /**
     * 检查Env中的值
     *
     * @param key
     * @param checkValue
     * @param defaultValue
     * @return
     */
    private static boolean checkEnvVariable(String key, String checkValue, String defaultValue) {
        return (checkValue.equals(EnvironmentVariable.getProperty(key, defaultValue)));
    }
}
